<% javascript 'backend/sortable' %>
<%= render 'backend/breadcrumbs' %>

<% @navigations.each do |n| %>
  <div class="row">
    <div class="col-md-6">
      <h2><%= n.description %></h2>
    </div>
    <div class="col-md-6 text-xs-right">
      <%= link_to t('b.add'), new_backend_navigation_item_path(n), class: 'btn btn-primary btn-sm' %>
    </div>
  </div>

  <% if n.items.any? %>
    <table class="table table-striped table-hover">
      <thead class="thead-inverse">
        <tr>
          <th><%= t 'b.page' %></th>
          <th><%= t 'b.custom_title' %></th>
          <th><%= t 'b.custom_url' %></th>
          <th><%= t 'b.extra' %></th>
          <th>&nbsp;</th>
        </tr>
      </thead>

      <tbody>
        <% n.items.each do |i| %>
          <tr data-update-position="<%= update_position_backend_navigation_item_path(n, i) %>">
            <td>
              <%= i.page ? i.page.description : t('b.none') %>
            </td>
            <td><%= i.translation.label %></td>
            <td><%= i.translation.path %></td>
            <td><%= i.extra %></td>
            <td class="text-xs-right">
              <%= link_to icon(:pencil_square_o), edit_backend_navigation_item_path(n, i) %>
              <%= link_to icon(:trash), backend_navigation_item_path(n, i), method: :delete, data: { confirm: t('b.msg.confirm') }%>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>

  <% else %>
    <p><%= t 'b.msg.no_items' %></p>
  <% end %>
<% end %>

<% if @navigations.empty? %>
  <div class="card">
    <div class="card-header">
      <%= t 'b.navigation' %>
    </div>

    <div class="card-block">
      <%= t 'b.msg.no_items' %>
    </div>
  </div>
<% end %>
